package com.fanxuankai.boot.mqbroker.consumer.autoconfigure;

import com.fanxuankai.boot.mqbroker.autoconfigure.Compensation;
import com.fanxuankai.boot.mqbroker.autoconfigure.MqBrokerProperties;
import com.fanxuankai.boot.mqbroker.consumer.EventStrategy;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.util.Collections;
import java.util.Map;

/**
 * @author fanxuankai
 */
@ConfigurationProperties(prefix = MqBrokerConsumerProperties.PREFIX)
public class MqBrokerConsumerProperties {
    public static final String PREFIX = MqBrokerProperties.PREFIX + ".consumer";
    public static final String ENABLED = PREFIX + ".enabled";
    /**
     * 是否开启消费者，开启后自动创建 MQ 的监听器
     */
    private boolean enabled = true;
    /**
     * 最大重试次数
     */
    private int maxRetry = 3;
    /**
     * 重试间隔 ms
     */
    private long retryInterval = 2_000;
    /**
     * 消费超时 ms
     */
    private long timeout = 300_000;
    /**
     * 手动签收
     */
    private boolean manualAcknowledge;
    /**
     * 事件策略, 可以配置相同事件多个消费者
     * key: 事件名 value: EventStrategy
     */
    private Map<String, EventStrategy> eventStrategy = Collections.emptyMap();
    /**
     * 是否开启消费补偿。
     * 开启：消费超时会进行消费补偿，会存在重复消费的问题，需要消费端做幂等处理；
     * 关闭：消费超时不会进行消费补偿，会存在消息状态一直处于进行中的问题，需要人工参与处理。
     */
    @NestedConfigurationProperty
    private Compensation compensation = new Compensation();
    /**
     * 慢消费者阈值 ms
     */
    private Long slowThreshold;

    public int getMaxRetry() {
        return maxRetry;
    }

    public void setMaxRetry(int maxRetry) {
        this.maxRetry = maxRetry;
    }

    public long getRetryInterval() {
        return retryInterval;
    }

    public void setRetryInterval(long retryInterval) {
        this.retryInterval = retryInterval;
    }

    public long getTimeout() {
        return timeout;
    }

    public void setTimeout(long timeout) {
        this.timeout = timeout;
    }

    public boolean isManualAcknowledge() {
        return manualAcknowledge;
    }

    public void setManualAcknowledge(boolean manualAcknowledge) {
        this.manualAcknowledge = manualAcknowledge;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public Map<String, EventStrategy> getEventStrategy() {
        return eventStrategy;
    }

    public void setEventStrategy(Map<String, EventStrategy> eventStrategy) {
        this.eventStrategy = eventStrategy;
    }

    public Compensation getCompensation() {
        return compensation;
    }

    public void setCompensation(Compensation compensation) {
        this.compensation = compensation;
    }

    public Long getSlowThreshold() {
        return slowThreshold;
    }

    public void setSlowThreshold(Long slowThreshold) {
        this.slowThreshold = slowThreshold;
    }
}
